package com.ywjh.inter.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class LocalDAO {
	public Map<String, String> getP(Connection conn) throws SQLException {
		Map<String, String> map = new HashMap<String, String>();
		PreparedStatement ps = conn.prepareStatement("select * from province order by id asc");
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			map.put(rs.getString("id"), rs.getString("name"));
		}
		rs.close();
		return map;
	}

	public Map<String, String> findCityByPid(Connection conn, int pid) throws SQLException {
		Map<String, String> map = new HashMap<String, String>();
		PreparedStatement ps = conn.prepareStatement("select * from city where province_id=?");
		ps.setInt(1, pid);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			map.put(rs.getString("id"), rs.getString("name"));
		}
		rs.close();
		return map;
	}

	public Map<String, String> findLocalbyCid(Connection conn, int cid) throws SQLException {
		Map<String, String> map = new HashMap<String, String>();
		PreparedStatement ps = conn.prepareStatement("select * from local where city_id=?");
		ps.setInt(1, cid);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			map.put(rs.getString("id"), rs.getString("name"));
		}
		rs.close();
		return map;
	}
}
